<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
插入排序：

时间复杂度，最好情况下是 O(n)，最坏情况下是 O(n方) <br>
适合小范围数组排序

<script>
	{

		function insertSort(arr) {
			if (arr.length <= 1) return arr

			let temp
			for (let i = 1; i < arr.length; i++) {
				temp = arr[i]
				let j = i
				while (j > 0 && temp < arr[j - 1]) {
					arr[j] = arr[j - 1]
					j--
				}

				arr[j] = temp
			}
			return arr
		}

		console.log(insertSort([9, 5, 3, 4, 100, 2, 1]))

	}
</script>
</body>
</html>
